package com.ljl.test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.entity.Deliver;
import com.entity.Deliverrecord;
import com.entity.Order;

import com.service.ljl.deliverservice;

public class delivertest {
	private deliverservice deliverservice;

	@Before
	public void init() {
		ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
		deliverservice = ac.getBean(deliverservice.class);
	}

	@After
	public void tearDown() {
		deliverservice = null;
	}

	@Test
	public void add() {
		Map map = new HashMap<>();
		Deliver deliver = new Deliver();
		map.put("deliver", deliver);
		map.put("orid", 2);
		map.put("proid", 4);
		deliverservice.add(map);
	}

	@Test
	public void delete() {
		deliverservice.delete(11L);
	}

	@Test
	public void findall() {
		Map<Object, Object> map = deliverservice.findall(10, 1);
		List<Deliver> li = (List<Deliver>) map.get("delivers");
		for (int i = 0; i < li.size(); i++) {
			System.out.println(li.get(i).getDeliverrecords().size());
		}
	}

	@Test
	public void findrecord() {
		Map<Object, Object> map = deliverservice.findrecord(10, 1);
		List<Deliverrecord> li = (List<Deliverrecord>) map.get("Deliverrecord");
		for (int i = 0; i < li.size(); i++) {
			System.out.println(li.get(i).getDeliver().getOrder().getOrTitle());
		}
	}

	@Test
	public void findcustomer() {
		for (int i = 0; i < deliverservice.findone(1L).size(); i++) {
			System.out.println(deliverservice.findone(1L).get(i).getOrTitle());
		}
	}

	@Test
	public void findpro() {
		Map map = deliverservice.productlist(9L);
		List<Deliver> li = (List<Deliver>) map.get("deliver");
		for (int i = 0; i < li.size(); i++) {
			System.out.println(li.get(i).getProduct().getName());
		}
	}

}
